package com.njchy.statistics.controller;


import com.njchy.statistics.service.AllServices;
import com.njchy.statistics.service.UploadFileService;
import com.njchy.statistics.util.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/upload")
@Api(tags = "文件上传功能模块")
public class UploadFileController {

    @Autowired
    private UploadFileService uploadFileService;


    /**
     * Excel文件数据写入数据库
     *
     * @param file
     * @return
     */
    @PostMapping("/excel")
    @ApiOperation("Excel文件数据写入数据库")
    public CommonResult getUploadExcel(@RequestParam("file") MultipartFile file) {
        boolean uploadExcel = uploadFileService.getUploadExcel(file);
        if (uploadExcel) {
            return CommonResult.success();
        }
        return CommonResult.failed(409, "数据重复，请检查！");
    }

    /**
     * 图片文件上传
     *
     * @param file
     * @return
     */
    @PostMapping("/image")
    @ApiOperation("图片文件上传")
    public CommonResult getUploadImages(@RequestParam("file") MultipartFile file) {
        return CommonResult.success(uploadFileService.getUploadImages(file));
    }




}
